package com.example.FirstBook.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.FirstBook.Bean.FoodBean;
import com.example.FirstBook.adapter.FoodNutritionItemAdapter;
import com.example.FirstBook.util.FoodUtil;
import com.example.myapplication.R;

import java.util.ArrayList;
import java.util.List;

/*
食物营养表
 */
public class Food_Nutrition_Activity extends AppCompatActivity {
    FoodNutritionItemAdapter adapter;
    private GridView foodNutritionGridview;
    List<FoodBean>list=new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_food__nutrition_);
        initView();
        list= FoodUtil.getFoodList();
        adapter=new FoodNutritionItemAdapter(this,list);
        foodNutritionGridview.setAdapter(adapter);
        //点击item跳转到详细的页面
        foodNutritionGridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                startActivity(new Intent(Food_Nutrition_Activity.this,Food_Details_Activity.class)
                        .putExtra("details",list.get(position)));
            }
        });
    }

    private void initView() {
        foodNutritionGridview = (GridView) findViewById(R.id.food_nutrition_gridview);

    }
}
